
exports.GameLoadingScreen = UI.View.subclass(
{
										
	classname: 'GameLoadingScreen',
	initialize: function() 
    {
		this._w = Core.Capabilities.getScreenWidth();
		this.progresslevel = 0;
		this._h = Core.Capabilities.getScreenHeight();
		this.setFrame([0,0,this._w,this._h]);
		this.text=["INITIALIZING_GAME","CONNECTING_TO_SERVER","LOADING_STORES","PARSING_STORES","SYNC_RESOURCES","CREATING_UI"];
		this.frame=[TCUtil.getAdjustedY(275),TCUtil.getAdjustedX(243),TCUtil.getAdjustedY(290),TCUtil.getAdjustedX(30)];
		this.firstTimeImage = null;
		NGWindow.document.addChild(this);
			
    },
    
	//function get image,label from UIFactory.Use image for setting background and label for setting status
	startLoadingScreen: function()
	{
     
		this._background = UIFactory.getImage([0,0,this._w, this._h], './Content/loading-screen.png');
		this.addChild(this._background);
		
		var frame = [TCUtil.getAdjustedX(20),TCUtil.getAdjustedY(20),TCUtil.getAdjustedX(100),TCUtil.getAdjustedY(50)];
		this._versionLabel = UIFactory.getTextArea(frame,null,16,[0,0],"ffffff",null);
		this._versionLabel.setText(TCUtil.getRelativeString( Core.Localization.getString("version") , [MM_VERSION_NUMBER]));
        //this.addChild(this._versionLabel);
        
        //this.dialog = new TransitionDialog();
		//this.addChild(this.dialog);
		
		var barRect = [TCUtil.getAdjustedY(245),TCUtil.getAdjustedX(265),TCUtil.getAdjustedY(205),TCUtil.getAdjustedX(20)];
			this.bar = new UI.ProgressBar({
			'frame': barRect,
			'progressGradient': {
				gradient: ["FF5a2d04 0.0", "FFd16a0d 1.0"],
				outerLine: "0000 4.0",
				innerLine: "0000 1.0",
				corners: '11',},
			'gradient': {
				gradient: ["FF00 0.0", "FF50 1.0"],
				outerLine: "FFb89c83 4.0",
				corners: '11',}
		});
		
		var spinnerRect = [TCUtil.getAdjustedX(140),TCUtil.getAdjustedY(60),TCUtil.getAdjustedWidth(120),TCUtil.getAdjustedHeight(40)];
		this.spinner=new UI.Spinner({
			'frame':spinnerRect,
			'textColor':"000000"});
		/*
		this.spinner.setGradient({
			gradient: ['FFFF8000 0.0', 'FF703300 1.0']
		}, UI.State.Normal);
		*/
		this.addChild(this.spinner);
		//this.addChild(this.bar);
        //NGWindow.document.addChild(this.bar);
        //NGWindow.document.addChild(this.spinner);
		this.bar.useForUpdateProgress(false);
		
		this.loadingState=UIFactory.getTextArea(this.frame,null,16,[0,0],"ffffff",null);
        //this.addChild(this.loadingState);
        
	},
	endLoadingScreen: function()
	{
		setTimeout(this.destroy.bind(this),500);
	},
	
	setLoadingImage: function() {
		if(this._background) {
			//ADDING IMAGE here as a child
			this.firstTimeImage = new UI.Image();
			this.firstTimeImage.setImage("./Content/first_run_image.png",UI.State.Normal);
			this.firstTimeImage.setFrame([TCUtil.getAdjustedY(250),TCUtil.getAdjustedX(100),TCUtil.getAdjustedY(220),TCUtil.getAdjustedX(100)]);
			this.firstTimeImage.setImageFit(UI.ViewGeometry.FitModes.Stretch);	      
			this.addChild(this.firstTimeImage);
		}
	},
	
    //function add current progress level and status
	updateProgress: function(progressStatus)
	{
		var progressFactor = 1/this.text.length;
		var progressToAdd = (progressFactor * progressStatus) + progressFactor;
		if(progressToAdd > this.progresslevel) {
			this.progresslevel = progressToAdd;	
			var myString = GALocalizationHandler.getLocalizedString(this.text[progressStatus]);
			this.loadingState.setText(myString);
			this.bar.setProgress(this.progresslevel);
		}
	},
	
	showProgressHud: function(msgText) {
		//Show progress Hud
		UIFactory.showProgressHUD(msgText);
	},
	
	updateProgressHud: function(msgText) {
		UIFactory.updateProgressHudText(msgText);
	},
	
	hideProgressHUD: function() {
		UIFactory.hideProgressHUD();
	},
	
	showProgressLabel: function(msgText) {
		return;
		var frame = [TCUtil.getAdjustedY(255),TCUtil.getAdjustedX(289),TCUtil.getAdjustedY(290),TCUtil.getAdjustedX(30)];
		this._progressLabel = UIFactory.getTextArea(frame,null,16,[0,0],"ffffff",null);
		this._progressLabel.setText(msgText);
        this.addChild(this._progressLabel);
	},

	updateProgressLabel: function(msgText) {
		if(this._progressLabel) {
			this._progressLabel.setText(msgText);
		}
	},

	hideProgressLabel: function() {
		if(this._progressLabel) {
			this._progressLabel.destroy();
			this._progressLabel = null;
		}
	},
	
	destroy: function()
	{
        //this.dialog.destroy();
        //this.dialog = null;
        
        this.spinner.destroy();
		this.spinner=null;
		this.bar.useForUpdateProgress(false);
		this.bar.destroy();
		this.bar=null;
        if(this.firstTimeImage)
        {
        	this.firstTimeImage.destroy();
        	this.firstTimeImage = null;
        	
        }
		this._background.destroy();
		this._background = null;
        
		this.loadingState.destroy();
		this.loadingState=null;
        
	},
	
});